(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

gt(0, y) → false
gt(s(x), 0) → true
gt(s(x), s(y)) → gt(x, y)
plus(0, y) → y
plus(s(x), y) → s(plus(x, y))
double(0) → 0
double(s(x)) → s(s(double(x)))
average(x, y) → aver(plus(x, y), 0)
aver(sum, z) → if(gt(sum, double(z)), sum, z)
if(true, sum, z) → aver(sum, s(z))
if(false, sum, z) → z

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
plus(0, y) → y [1]
plus(s(x), y) → s(plus(x, y)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]
average(x, y) → aver(plus(x, y), 0) [1]
aver(sum, z) → if(gt(sum, double(z)), sum, z) [1]
if(true, sum, z) → aver(sum, s(z)) [1]
if(false, sum, z) → z [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
plus(0, y) → y [1]
plus(s(x), y) → s(plus(x, y)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]
average(x, y) → aver(plus(x, y), 0) [1]
aver(sum, z) → if(gt(sum, double(z)), sum, z) [1]
if(true, sum, z) → aver(sum, s(z)) [1]
if(false, sum, z) → z [1]

The TRS has the following type information:
gt :: 0:s → 0:s → false:true
0 :: 0:s
false :: false:true
s :: 0:s → 0:s
true :: false:true
plus :: 0:s → 0:s → 0:s
double :: 0:s → 0:s
average :: 0:s → 0:s → 0:s
aver :: 0:s → 0:s → 0:s
if :: false:true → 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
plus(0, y) → y [1]
plus(s(x), y) → s(plus(x, y)) [1]
double(0) → 0 [1]
double(s(x)) → s(s(double(x))) [1]
average(x, y) → aver(plus(x, y), 0) [1]
aver(sum, z) → if(gt(sum, double(z)), sum, z) [1]
if(true, sum, z) → aver(sum, s(z)) [1]
if(false, sum, z) → z [1]

The TRS has the following type information:
gt :: 0:s → 0:s → false:true
0 :: 0:s
false :: false:true
s :: 0:s → 0:s
true :: false:true
plus :: 0:s → 0:s → 0:s
double :: 0:s → 0:s
average :: 0:s → 0:s → 0:s
aver :: 0:s → 0:s → 0:s
if :: false:true → 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
false => 0
true => 1

(8) Obligation:

Complexity RNTS consisting of the following rules:

aver(z', z'') -{ 1 }→ if(gt(sum, double(z)), sum, z) :|: z'' = z, z >= 0, sum >= 0, z' = sum
average(z', z'') -{ 1 }→ aver(plus(x, y), 0) :|: z' = x, z'' = y, x >= 0, y >= 0
double(z') -{ 1 }→ 0 :|: z' = 0
double(z') -{ 1 }→ 1 + (1 + double(x)) :|: z' = 1 + x, x >= 0
gt(z', z'') -{ 1 }→ gt(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
gt(z', z'') -{ 1 }→ 1 :|: z'' = 0, z' = 1 + x, x >= 0
gt(z', z'') -{ 1 }→ 0 :|: z'' = y, y >= 0, z' = 0
if(z', z'', z1) -{ 1 }→ z :|: z1 = z, z >= 0, sum >= 0, z'' = sum, z' = 0
if(z', z'', z1) -{ 1 }→ aver(sum, 1 + z) :|: z1 = z, z >= 0, z' = 1, sum >= 0, z'' = sum
plus(z', z'') -{ 1 }→ y :|: z'' = y, y >= 0, z' = 0
plus(z', z'') -{ 1 }→ 1 + plus(x, y) :|: z' = 1 + x, z'' = y, x >= 0, y >= 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V14),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14),0,[plus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14),0,[double(V, Out)],[V >= 0]).
eq(start(V, V1, V14),0,[average(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14),0,[aver(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14),0,[if(V, V1, V14, Out)],[V >= 0,V1 >= 0,V14 >= 0]).
eq(gt(V, V1, Out),1,[],[Out = 0,V1 = V2,V2 >= 0,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 1,V1 = 0,V = 1 + V3,V3 >= 0]).
eq(gt(V, V1, Out),1,[gt(V4, V5, Ret)],[Out = Ret,V = 1 + V4,V4 >= 0,V5 >= 0,V1 = 1 + V5]).
eq(plus(V, V1, Out),1,[],[Out = V6,V1 = V6,V6 >= 0,V = 0]).
eq(plus(V, V1, Out),1,[plus(V7, V8, Ret1)],[Out = 1 + Ret1,V = 1 + V7,V1 = V8,V7 >= 0,V8 >= 0]).
eq(double(V, Out),1,[],[Out = 0,V = 0]).
eq(double(V, Out),1,[double(V9, Ret11)],[Out = 2 + Ret11,V = 1 + V9,V9 >= 0]).
eq(average(V, V1, Out),1,[plus(V10, V11, Ret0),aver(Ret0, 0, Ret2)],[Out = Ret2,V = V10,V1 = V11,V10 >= 0,V11 >= 0]).
eq(aver(V, V1, Out),1,[double(V13, Ret01),gt(V12, Ret01, Ret02),if(Ret02, V12, V13, Ret3)],[Out = Ret3,V1 = V13,V13 >= 0,V12 >= 0,V = V12]).
eq(if(V, V1, V14, Out),1,[aver(V15, 1 + V16, Ret4)],[Out = Ret4,V14 = V16,V16 >= 0,V = 1,V15 >= 0,V1 = V15]).
eq(if(V, V1, V14, Out),1,[],[Out = V17,V14 = V17,V17 >= 0,V18 >= 0,V1 = V18,V = 0]).
input_output_vars(gt(V,V1,Out),[V,V1],[Out]).
input_output_vars(plus(V,V1,Out),[V,V1],[Out]).
input_output_vars(double(V,Out),[V],[Out]).
input_output_vars(average(V,V1,Out),[V,V1],[Out]).
input_output_vars(aver(V,V1,Out),[V,V1],[Out]).
input_output_vars(if(V,V1,V14,Out),[V,V1,V14],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [double/2]
1. recursive : [gt/3]
2. recursive : [aver/3,if/4]
3. recursive : [plus/3]
4. non_recursive : [average/3]
5. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into double/2
1. SCC is partially evaluated into gt/3
2. SCC is partially evaluated into aver/3
3. SCC is partially evaluated into plus/3
4. SCC is partially evaluated into average/3
5. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations double/2
* CE 17 is refined into CE [19]
* CE 16 is refined into CE [20]


### Cost equations --> "Loop" of double/2
* CEs [20] --> Loop 13
* CEs [19] --> Loop 14

### Ranking functions of CR double(V,Out)
* RF of phase [14]: [V]

#### Partial ranking functions of CR double(V,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V


### Specialization of cost equations gt/3
* CE 13 is refined into CE [21]
* CE 12 is refined into CE [22]
* CE 11 is refined into CE [23]


### Cost equations --> "Loop" of gt/3
* CEs [22] --> Loop 15
* CEs [23] --> Loop 16
* CEs [21] --> Loop 17

### Ranking functions of CR gt(V,V1,Out)
* RF of phase [17]: [V,V1]

#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V
V1


### Specialization of cost equations aver/3
* CE 10 is refined into CE [24,25]
* CE 9 is refined into CE [26,27,28]


### Cost equations --> "Loop" of aver/3
* CEs [28] --> Loop 18
* CEs [27] --> Loop 19
* CEs [26] --> Loop 20
* CEs [25] --> Loop 21
* CEs [24] --> Loop 22

### Ranking functions of CR aver(V,V1,Out)
* RF of phase [21]: [V/2-V1]

#### Partial ranking functions of CR aver(V,V1,Out)
* Partial RF of phase [21]:
- RF of loop [21:1]:
V/2-V1


### Specialization of cost equations plus/3
* CE 15 is refined into CE [29]
* CE 14 is refined into CE [30]


### Cost equations --> "Loop" of plus/3
* CEs [30] --> Loop 23
* CEs [29] --> Loop 24

### Ranking functions of CR plus(V,V1,Out)
* RF of phase [24]: [V]

#### Partial ranking functions of CR plus(V,V1,Out)
* Partial RF of phase [24]:
- RF of loop [24:1]:
V


### Specialization of cost equations average/3
* CE 18 is refined into CE [31,32,33,34,35]


### Cost equations --> "Loop" of average/3
* CEs [35] --> Loop 25
* CEs [34] --> Loop 26
* CEs [33] --> Loop 27
* CEs [32] --> Loop 28
* CEs [31] --> Loop 29

### Ranking functions of CR average(V,V1,Out)

#### Partial ranking functions of CR average(V,V1,Out)


### Specialization of cost equations start/3
* CE 3 is refined into CE [36,37,38]
* CE 2 is refined into CE [39]
* CE 4 is refined into CE [40,41,42,43]
* CE 5 is refined into CE [44,45]
* CE 6 is refined into CE [46,47]
* CE 7 is refined into CE [48,49,50,51,52]
* CE 8 is refined into CE [53,54,55,56,57,58]


### Cost equations --> "Loop" of start/3
* CEs [38] --> Loop 30
* CEs [37] --> Loop 31
* CEs [36,41,42,43,45,47,51,52,55,56,57,58] --> Loop 32
* CEs [39,40,44,46,48,49,50,53,54] --> Loop 33

### Ranking functions of CR start(V,V1,V14)

#### Partial ranking functions of CR start(V,V1,V14)


Computing Bounds
=====================================

#### Cost of chains of double(V,Out):
* Chain [[14],13]: 1*it(14)+1
Such that:it(14) =< Out/2

with precondition: [2*V=Out,V>=1]

* Chain [13]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of gt(V,V1,Out):
* Chain [[17],16]: 1*it(17)+1
Such that:it(17) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[17],15]: 1*it(17)+1
Such that:it(17) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [16]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [15]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of aver(V,V1,Out):
* Chain [[21],18]: 4*it(21)+1*s(1)+1*s(2)+1*s(7)+1*s(8)+4
Such that:s(2) =< V
aux(1) =< V/2+1/2
it(21) =< V/2-V1
s(1) =< Out
aux(2) =< it(21)*aux(1)
s(7) =< it(21)*aux(1)
s(8) =< aux(2)*2

with precondition: [V1>=1,V+1>=2*Out,2*Out>=V,Out>=V1+1]

* Chain [22,[21],18]: 4*it(21)+1*s(1)+1*s(2)+1*s(7)+1*s(8)+8
Such that:s(2) =< V
it(21) =< V/2
aux(1) =< V/2+1/2
s(1) =< Out
aux(2) =< it(21)*aux(1)
s(7) =< it(21)*aux(1)
s(8) =< aux(2)*2

with precondition: [V1=0,Out>=2,V+1>=2*Out,2*Out>=V]

* Chain [22,18]: 1*s(1)+1*s(2)+8
Such that:s(1) =< 1
s(2) =< V

with precondition: [V1=0,Out=1,2>=V,V>=1]

* Chain [20]: 4
with precondition: [V=0,V1=0,Out=0]

* Chain [19]: 1*s(9)+4
Such that:s(9) =< V1

with precondition: [V=0,V1=Out,V1>=1]

* Chain [18]: 1*s(1)+1*s(2)+4
Such that:s(2) =< V
s(1) =< V1

with precondition: [V1=Out,V>=1,V1>=1,2*V1>=V]


#### Cost of chains of plus(V,V1,Out):
* Chain [[24],23]: 1*it(24)+1
Such that:it(24) =< -V1+Out

with precondition: [V+V1=Out,V>=1,V1>=0]

* Chain [23]: 1
with precondition: [V=0,V1=Out,V1>=0]


#### Cost of chains of average(V,V1,Out):
* Chain [29]: 6
with precondition: [V=0,V1=0,Out=0]

* Chain [28]: 1*s(10)+1*s(11)+10
Such that:s(10) =< 1
s(11) =< V1

with precondition: [V=0,Out=1,2>=V1,V1>=1]

* Chain [27]: 1*s(12)+4*s(13)+1*s(15)+1*s(17)+1*s(18)+10
Such that:s(12) =< V1
s(13) =< V1/2
aux(3) =< V1/2+1/2
s(15) =< aux(3)
s(16) =< s(13)*aux(3)
s(17) =< s(13)*aux(3)
s(18) =< s(16)*2

with precondition: [V=0,Out>=2,V1+1>=2*Out,2*Out>=V1]

* Chain [26]: 1*s(19)+1*s(20)+1*s(21)+10
Such that:s(20) =< 1
s(19) =< V
s(21) =< V+V1

with precondition: [Out=1,V>=1,V1>=0,2>=V+V1]

* Chain [25]: 1*s(22)+1*s(23)+4*s(24)+1*s(26)+1*s(28)+1*s(29)+10
Such that:s(22) =< V
s(23) =< V+V1
s(24) =< V/2+V1/2
aux(4) =< V/2+V1/2+1/2
s(26) =< aux(4)
s(27) =< s(24)*aux(4)
s(28) =< s(24)*aux(4)
s(29) =< s(27)*2

with precondition: [V>=1,V1>=0,Out>=2,V+V1+1>=2*Out,2*Out>=V+V1]


#### Cost of chains of start(V,V1,V14):
* Chain [33]: 1*s(30)+3*s(31)+4*s(33)+1*s(35)+1*s(37)+1*s(38)+10
Such that:s(30) =< 1
s(33) =< V1/2
s(34) =< V1/2+1/2
aux(5) =< V1
s(31) =< aux(5)
s(35) =< s(34)
s(36) =< s(33)*s(34)
s(37) =< s(33)*s(34)
s(38) =< s(36)*2

with precondition: [V=0]

* Chain [32]: 1*s(40)+9*s(41)+2*s(42)+2*s(45)+2*s(47)+4*s(50)+1*s(52)+1*s(54)+1*s(55)+4*s(59)+2*s(61)+1*s(63)+1*s(64)+4*s(69)+1*s(72)+1*s(73)+10
Such that:s(59) =< V/2
s(69) =< V/2-V1
s(50) =< V/2+V1/2
s(51) =< V/2+V1/2+1/2
s(40) =< V14+1
aux(8) =< 1
aux(9) =< V
aux(10) =< V+V1
aux(11) =< V/2+1/2
aux(12) =< V1
s(45) =< aux(8)
s(41) =< aux(9)
s(47) =< aux(10)
s(42) =< aux(12)
s(52) =< s(51)
s(53) =< s(50)*s(51)
s(54) =< s(50)*s(51)
s(55) =< s(53)*2
s(61) =< aux(11)
s(62) =< s(59)*aux(11)
s(63) =< s(59)*aux(11)
s(64) =< s(62)*2
s(71) =< s(69)*aux(11)
s(72) =< s(69)*aux(11)
s(73) =< s(71)*2

with precondition: [V>=1]

* Chain [31]: 1*s(74)+1*s(75)+5
Such that:s(74) =< V1
s(75) =< V14+1

with precondition: [V=1,V1>=1,V14>=0,2*V14+2>=V1]

* Chain [30]: 1*s(76)+4*s(78)+1*s(79)+1*s(81)+1*s(82)+5
Such that:s(76) =< V1
s(78) =< V1/2-V14
aux(13) =< V1/2+1/2
s(79) =< aux(13)
s(80) =< s(78)*aux(13)
s(81) =< s(78)*aux(13)
s(82) =< s(80)*2

with precondition: [V=1,V14>=0,V1>=2*V14+3]


Closed-form bounds of start(V,V1,V14):
-------------------------------------
* Chain [33] with precondition: [V=0]
- Upper bound: nat(V1)*3+11+nat(V1/2+1/2)+nat(V1/2+1/2)*3*nat(V1/2)+nat(V1/2)*4
- Complexity: n^2
* Chain [32] with precondition: [V>=1]
- Upper bound: 9*V+12+nat(V1)*2+nat(V+V1)*2+nat(V14+1)+nat(V/2+V1/2+1/2)+nat(V/2+V1/2+1/2)*3*nat(V/2+V1/2)+nat(V/2+V1/2)*4+ (V+1)+ (3/2*V+3/2)*nat(V/2-V1)+V/2* (3/2*V+3/2)+nat(V/2-V1)*4+2*V
- Complexity: n^2
* Chain [31] with precondition: [V=1,V1>=1,V14>=0,2*V14+2>=V1]
- Upper bound: V1+V14+6
- Complexity: n
* Chain [30] with precondition: [V=1,V14>=0,V1>=2*V14+3]
- Upper bound: 2*V1-4*V14+ (3/2*V1+11/2+ (V1/2-V14)* (3/2*V1+3/2))
- Complexity: n^2

### Maximum cost of start(V,V1,V14): nat(V1)+5+max([max([nat(V14+1),nat(V1/2+1/2)*3*nat(V1/2-V14)+nat(V1/2+1/2)+nat(V1/2-V14)*4]),nat(V1)+6+max([nat(V1/2+1/2)+nat(V1)+nat(V1/2+1/2)*3*nat(V1/2)+nat(V1/2)*4,9*V+1+nat(V+V1)*2+nat(V14+1)+nat(V/2+V1/2+1/2)+nat(V/2+V1/2+1/2)*3*nat(V/2+V1/2)+nat(V/2+V1/2)*4+ (V+1)+ (3/2*V+3/2)*nat(V/2-V1)+V/2* (3/2*V+3/2)+nat(V/2-V1)*4+2*V])])
Asymptotic class: n^2
* Total analysis performed in 348 ms.

(10) BOUNDS(1, n^2)